import type { PersistenceOptions } from 'pinia-plugin-persistedstate';

/**
 * 配置 pinia 持久化存储的选项
 * @param key 存储在持久化存储中的键名
 * @param paths 要持久化的 state 路径数组
 * @param storage 存储引擎，默认为 localStorage
 * @returns 持久化配置选项
 */
const piniaPersistConfig = (
  key: string,
  paths?: string[],
  storage: Storage = localStorage,
): PersistenceOptions => {
  if (!key) {
    throw new Error('Key is required for pinia persistence configuration');
  }
  const persist: PersistenceOptions & { paths?: string[] } = {
    key,
    storage,
    ...(paths && { paths }),
  };
  return persist;
};

export default piniaPersistConfig;
